package com.cong.leetcode.util;
import java.util.Random;

public class MyRandom {
    static Random random = new Random();

    public static int randIntRange(int begin, int end) {
        if (begin >= end) {
            return  0;
        }
        return random.nextInt(end - begin + 1) +  begin;
    }
    public static int[] randArray(int [] array) {
        int len = array.length;
        for (int i = 0; i < len - 1; i++) {
            int targetIndex = randIntRange(i, len - 1);
            int temp = array[targetIndex];
            array[targetIndex] = array[i];
            array[i] = temp;
        }
        return array;
    }
}
